<template>
	<view>
		<phone-directory :phones="phones" @paramClick="paramClick"></phone-directory>
	</view>
</template>

<script>
	import phoneDirectory from '@/components/phone-directory/phone-directory.vue'
	export default {
		name:"phones",
		components:{
			phoneDirectory
		},
		data() {
			return {
				//示例数据
				phones:{},
				options: {}
				
			}
		},
		async onLoad(options) {
			this.options = options;
			let title = '选择';
			let result = null;
			if (options.type == 'club') {
				title += ' Club';
				result = await this.$api.listAllClub({indexed: 1});
			} else if (options.type == 'technician') {
				title += ' Technician';
				result = await this.$api.listAllTechnician({indexed: 1});
			}
			uni.setNavigationBarTitle({
				title: title
			})
			if (result && result.ret == 0) {
				this.phones = result.data;
				// this.phones = {
				// 	"A": [{
				// 		"id": 1,
				// 		"name": "张三",
				// 		"spell": "zhangsan"
				// 	},{
				// 		"id": 1,
				// 		"name": "张三",
				// 		"spell": "zhangsan"
				// 	},{
				// 		"id": 1,
				// 		"name": "张三",
				// 		"spell": "zhangsan"
				// 	}]
				// }
			}
			
		},
		methods : {
			paramClick (e) {
				console.log(e)
				let item = {
					id: e.id,
					name: e.name
				}
				console.log(this.options, item)
				if (this.options.type == 'club') {
					this.$store.commit('setSelectedClub', item)
				} else if (this.options.type == 'technician') {
					this.$store.commit('setSelectedTechnician', item)
				}
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style>

</style>
